#include <string>
#include<iostream>
using namespace std;
class Solution {
public:
    string replaceSpaces(string S, int length) {
        string s1;
        for (int i = 0; i < length; i++)
        {
            if (S[i] == ' ')
            {
                s1 += "%20";
            }
            else {
                s1 += S[i];
            }
        }
        return s1;
    }
};

class Solution {
public:
    string compressString(string S) {
        S += 'A';
        string s1;
        int count = 1;
        for (int i = 1; i < S.size(); i++)
        {
            if (S[i] == S[i - 1]) {
                count++;
            }
            else {
                s1 += S[i - 1];
                s1 += to_string(count);
                count = 1;
            }

        }
        if (S.size() - 1 > s1.size())
        {
            return s1;
        }
        S.erase(S.size() - 1);
        return S;
    }
};

class Solution {
public:
    int exchangeBits(int num) {
        int ou = 0b10101010101010101010101010101010;
        int ji = 0b01010101010101010101010101010101;
        ou &= num;
        ji &= num;
        return ((ou >> 1) + (ji << 1));
    }
};

class Solution {
public:
    int multiply(int A, int B) {
        int sum = 0;
        for (int i = 0; i < B; i++)
        {
            sum += A;
        }
        return sum;
    }
};